<?php
/*
 * @Description  : 权限管理
 * @Author       : https://github.com/skyselang
 * @Date         : 2020-05-05
 * @LastEditTime : 2020-12-25
 */

namespace app\store\service;

use app\store\model\SystemConfig as ModelSystemConfig;

class SystemConfig
{

    /**
     * 配置查询
     * @param array $key
     * @return array
     */
    public static function get(array $key)
    {
        $where[] = ['key', 'in', $key];
        $field = 'key,value';
        $data = ModelSystemConfig::getList($field, $where);
        $datas = [];
        foreach ($data as $item) {
            $datas[$item['key']] = $item['value'];
        }
        return $datas;
    }

    /**
     * 批量配置设置
     * @param 
     */
    public static function batchSet(array $data)
    {
        $time = date('Y-m-d H:i:s');
        foreach ($data as $item) {
            //查询是否存在，存在则修改，不存在则新增
            if (ModelSystemConfig::getCount([
                'key' => $item['key']
            ])) {
                //修改
                $item['update_time'] = $time;
                ModelSystemConfig::update($item, ['key' => $item['key']]);
            } else {
                //新增
                $item['create_time'] = $time;
                ModelSystemConfig::create($item);
            }
        }
    }
}
